package test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class ConnectionManager {
	private static ConnectionManager connectionManager;
	private Connection conn;

	private ConnectionManager() {
	}

	public static ConnectionManager getInstance() {
		if (connectionManager == null) {
			connectionManager = new ConnectionManager();
		}
		return connectionManager;
	}

	public Connection getConn() {
		if (conn == null) {
			try {
				Class.forName("oracle.jdbc.driver.OracleDriver"); // ドライバのロード
				String jdbcUrl = "jdbc:oracle:thin:@DIO:1521:LUCKYLAND"; // 接続文字列

				Properties prop = new Properties();
				prop.put("user", "ARAKI");
				prop.put("password", "HIROHIKO");
				prop.put("useUnicode", "true");
				prop.put("characterEncoding", "utf8");
				// コネクションの取得
				conn = DriverManager.getConnection(jdbcUrl, prop);

			} catch (ClassNotFoundException e) {
				System.err.println("JDBCドライバがロードできません。");
				e.printStackTrace();
			} catch (SQLException e) {
				System.err.println("SQLエラーです。");
				e.printStackTrace();
			}
		}
		return conn;
	}
}
